﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraPrintingLinks;
using DevExpress.XtraPrinting;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid;
using DevExpress.Utils;

namespace NNLInterface
{
    public partial class common 
    {
        //2007/12/27保存listview的新布局
        public static void SaveLayout(DevExpress.XtraGrid.Views.Grid.GridView ListView)
        {
            try
            {
                DevExpress.Utils.OptionsLayoutGrid opt = new DevExpress.Utils.OptionsLayoutGrid();
                opt.StoreAllOptions = false;
                opt.Columns.StoreAllOptions = false;
                opt.Columns.StoreLayout = true;
                //opt.Columns.StoreAppearance = true;
                opt.StoreVisualOptions = true;
                //opt.StoreDataSettings = true;
                ListView.OptionsLayout.Assign(opt);
                ListView.SaveLayoutToXml(common.GetSolutionPath(Application.StartupPath) + @"GridLayout\" + Application.ProductName + "." + ListView.GridControl.Parent.Name + "." + ListView.GridControl.Name + "." + ListView.Name + ".xml");

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, sysParameter.MessageInf, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }

        public static void SaveLayout(DevExpress.XtraGrid.Views.Grid.GridView ListView, string frmName)
        {
            try
            {
                DevExpress.Utils.OptionsLayoutGrid opt = new DevExpress.Utils.OptionsLayoutGrid();
                opt.StoreAllOptions = true;
                opt.Columns.StoreAllOptions = true;
                opt.Columns.StoreLayout = true;
                opt.Columns.StoreAppearance = true;
                opt.StoreVisualOptions = true;
                opt.StoreDataSettings = true;
                ListView.OptionsLayout.Assign(opt);
                ListView.SaveLayoutToXml(common.GetSolutionPath(Application.StartupPath) + @"GridLayout\" + Application.ProductName + "." + ListView.GridControl.Parent.Name + "." + frmName + "." + ListView.GridControl.Name + "." + ListView.Name + ".xml");

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, sysParameter.MessageInf, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }

        public static void SaveToolBarLayout(string frmName, DevExpress.XtraBars.BarManager barManager)
        {
            try
            {
                barManager.SaveLayoutToXml(common.GetSolutionPath(System.Windows.Forms.Application.StartupPath) + @"GridLayout\" + System.Windows.Forms.Application.ProductName + "." + frmName + ".xml");
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存窗体布局失败!", sysParameter.MessageInf, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }


        public static void ReStoreToolBarLayout(string frmName, DevExpress.XtraBars.BarManager barManager)
        {
            if (System.IO.File.Exists(common.GetSolutionPath(Application.StartupPath) + @"GridLayout\" + Application.ProductName + "." + frmName + ".xml"))
                barManager.RestoreLayoutFromXml(common.GetSolutionPath(Application.StartupPath) + @"GridLayout\" + Application.ProductName + "." + frmName + ".xml");

        }

        public static void ReStoreLayOut(DevExpress.XtraGrid.Views.Grid.GridView ListView, string frmName)
        {
            if (System.IO.File.Exists(common.GetSolutionPath(Application.StartupPath) + @"GridLayout\" + Application.ProductName + "." + ListView.GridControl.Parent.Name + "." + frmName + "." + ListView.GridControl.Name + "." + ListView.Name + ".xml"))
                ListView.RestoreLayoutFromXml(common.GetSolutionPath(Application.StartupPath) + @"GridLayout\" + Application.ProductName + "." + ListView.GridControl.Parent.Name + "." + frmName + "." + ListView.GridControl.Name + "." + ListView.Name + ".xml");
        }

        public static void ReStoreLayOut(DevExpress.XtraGrid.Views.Grid.GridView ListView)
        {
            if (System.IO.File.Exists(common.GetSolutionPath(Application.StartupPath) + @"GridLayout\" + Application.ProductName + "." + ListView.GridControl.Parent.Name + "." + ListView.GridControl.Name + "." + ListView.Name + ".xml"))
                ListView.RestoreLayoutFromXml(common.GetSolutionPath(Application.StartupPath) + @"GridLayout\" + Application.ProductName + "." + ListView.GridControl.Parent.Name + "." + ListView.GridControl.Name + "." + ListView.Name + ".xml");
        }

        public static void ReStoreLayOut(DevExpress.XtraGrid.Views.BandedGrid.AdvBandedGridView ListView)
        {
            if (System.IO.File.Exists(common.GetSolutionPath(Application.StartupPath) + @"GridLayout\" + Application.ProductName + "." + ListView.GridControl.Parent.Name + "." + ListView.GridControl.Name + "." + ListView.Name + ".xml"))
                ListView.RestoreLayoutFromXml(common.GetSolutionPath(Application.StartupPath) + @"GridLayout\" + Application.ProductName + "." + ListView.GridControl.Parent.Name + "." + ListView.GridControl.Name + "." + ListView.Name + ".xml");
        }

        public static void SaveFormLayOut(string frmStance ,DevExpress.XtraLayout.LayoutControl layOut, Control  grpHead)
        {
            layOut.SaveLayoutToXml(common.GetSolutionPath(Application.StartupPath) + @"FormLayout\" + Application.ProductName + "." + frmStance + ".xml");
            common.RWLang.WriteTextFile(frmStance, "grpHead", grpHead.Height.ToString());

        }

        public static void SaveFormLayOut(Form frmStance, DevExpress.XtraLayout.LayoutControl layOut, Control grpHead)
        {
            layOut.SaveLayoutToXml(common.GetSolutionPath(Application.StartupPath) + @"FormLayout\" + Application.ProductName + "." + frmStance.Name + ".xml");
            common.RWLang.WriteTextFile(frmStance.Name, "grpHead", grpHead.Height.ToString());

        }

        public static void RestoreFormLayOut(string frmStance, DevExpress.XtraLayout.LayoutControl layOut, Control grpHead)
        {
            if (System.IO.File.Exists(common.GetSolutionPath(Application.StartupPath) + @"FormLayout\" + Application.ProductName + "." + frmStance+ ".xml"))
                layOut.RestoreLayoutFromXml(common.GetSolutionPath(Application.StartupPath) + @"FormLayout\" + Application.ProductName + "." + frmStance + ".xml");
            string strLocation = common.GetLanguageWord(frmStance, "grphead");
            if (!strLocation.Equals("0"))
                grpHead.Height = Convert.ToInt32(strLocation);
        }


        public static void RestoreFormLayOut(Form frmStance, DevExpress.XtraLayout.LayoutControl layOut, Control grpHead)
        {
            if (System.IO.File.Exists(common.GetSolutionPath(Application.StartupPath) + @"FormLayout\" + Application.ProductName + "." + frmStance.Name + ".xml"))
                layOut.RestoreLayoutFromXml(common.GetSolutionPath(Application.StartupPath) + @"FormLayout\" + Application.ProductName + "." + frmStance.Name + ".xml");
            string strLocation = common.GetLanguageWord(frmStance.Name, "grphead");
            if (!strLocation.Equals("0"))
                grpHead.Height = Convert.ToInt32(strLocation);
        }
    }
}
